<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		表单验证
		<script src="validate.js"></script>
		<script type="text/javascript">
			const formData={
				email:'1@qq.com',
				username:'1',
				tel:'13527464821',
				pwd:'123456',
				pwd2:'123456',
				telCode:'124567',
				zipCode:'400000'
			}
			const formRules = [
			  {name: 'email',required:true, type: 'email'},
			  {name: 'username',required:true},
			  {name: 'tel', required: true, type: 'mobile',emptyMsg:"请输入手机号", errMsg: '请输入正确的手机号'},
			  {name: 'pwd',required:true, type: 'lengthRange',min: 6,max: 16, emptyMsg: '请输入密码', errMsg: '密码须是6-16位字符'},
			  {name: 'pwd2',required:true, type: 'equals', eqName: 'pwd',emptyMsg: '请再次输入密码', errMsg: '两次输入密码不一致'},
			  {name: 'telCode',required: true, type: 'inviteCode',emptyMsg: '请输入验证码', errMsg: '请输入正确的验证码格式'},
			  {name: 'telCode', type: 'lengthRange', min: 6, max: 6, errMsg: '验证码必须是6位字符'},
			  {name: 'zipCode',required:true, type: 'zipCode', emptyMsg:"请输入zipCode",errMsg: '请输入正确的zipCode'},
			]
			let validate = new Validate(formData,formRules)
			// 自定义校验规则
			validate.addRule('zipCode',(val,msg)=>{
				var reg = /^[0-9]{6}$/;
				if(!reg.test(val)){
					return msg
				}
			})
			// 验证检测
			let result = validate.check()
			if(!result.isOk){
				console.log(result.msg)
			}else{
				console.log('校验完成');
			}
		</script>
	</body>
</html>
